package org.capgemini.tienda.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Cifrar {		
	public static String conMD5(final String origen) throws NoSuchAlgorithmException{
		
		final MessageDigest md = MessageDigest.getInstance("md5");
        md.update(origen.getBytes());        
        return toHex(md.digest());
	}
	
	private static String toHex(byte[] raw) {
        StringBuilder sb = new StringBuilder(raw.length * 2);
        for (int i = 0; i < raw.length; i++) {
            sb.append(Character.forDigit((raw[i] & 0xf0) >> 4, 16));
            sb.append(Character.forDigit(raw[i] & 0x0f, 16));
        }
        return sb.toString();
    }
	
	public static void main(String[] args) {
		try {
			System.out.println(Cifrar.conMD5("admin"));
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
